<template>
  <div>
    <div class="mtb20">
      <el-form inline size="medium" class="mtb20" :model="moduleData">
        <el-form-item label="大标题：">
          <el-input v-model="variables.title" placeholder="精华都市"></el-input>
        </el-form-item>
        <el-form-item label="小标题：">
          <el-input v-model="variables.subTitle" placeholder="Kelly GlobalMarket"></el-input>
        </el-form-item>
      </el-form>
      <div class="mtb20">
        <el-button type="success" @click="addSecondCategory">添加二级分类</el-button>
        <pcTableAdd :tableData="variables.secondTitleTableData"></pcTableAdd>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close()" size="mini">取消</el-button>
      <el-button type="primary" @click="saveModuleData" size="mini">确定</el-button>
    </div>
  </div>
</template>
<script>
import pcTableAdd from ".././component/pcTableAdd"; //添加二级分类
export default {
  props: {
    //模块Id
    moduleId: {
      type: String
    },
    moduleData: {
      type: Object,
      default: () => {
        return {};
      }
    },
    //上传文件的列表
    fileList: {
      type: Array,
      default: () => {
        return []
      }
    },
  },
  components: {
    pcTableAdd
  },
  data() {
    return {
      variables :{
        title: null,
        subTitle: null,
        secondTitleTableData: [],
        bigImgList: [],
      },
    };
  },

  mounted(){
    //对象当中包含对象,需要JSON解析一下;
    if (this !== null && this.moduleData !== null
      && this.moduleData.variables !== null
      && this.moduleData.variables !== ''
      && this.moduleData.variables !== ""
    ) {
      this.variables = this.moduleData.variables;
    }
  },


  methods: {
    //上传二级目录
    addSecondCategory() {
      this.variables.secondTitleTableData.push({
        name: "",
        imgLink: ""
      });
    },

    /**
     * 保存模块数据
     */
    saveModuleData(){
      let this_ = this;
      let params = {};
      params.templateDataType = 0;
      params.moduleId = this_.moduleData.cmsModuleId;
      params.platform = 2;


      params.variablesObject = {
        title: this_.variables.title,
        subTitle: this_.variables.subTitle,
        secondTitleTableData: this_.variables.secondTitleTableData,
      };
      this_.utils.request.cmsPageModuleAddModuleData(params, res => {
        if (res.code === "0000") {
          this_.$emit('getIndex');
          this_.$message({"message": "保存成功", type: "success"});
        } else {
          this_.variables={};
          this_.$message({"message": res.msg, type: "error"});
        }
      })
    },

    /**
     * 返回上一页
     */
    close(){
      this.$router.push("/Pages/Configuration/IndexShow");
    },


  }
};
</script>
<style lang="scss" scoped>
.mtb20 {
  margin: 20px 0;
  text-align: left;
}
.el-button {
  margin-bottom: 5px;
  text-align: left;
}
.productProduct {
  text-align: left;
}
</style>
